﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Chapter12.Code04
{
    public class Demo
    {
        public static void Begin()
        {
            {
                Cow myCow = new Cow("Geronimo");
                Animal myAnimal = myCow;
            }
            {
                Cow myCow = new Cow("Geronimo");
                IMethaneProducer<Cow> cowMethaneProducer = myCow;
                IMethaneProducer<Animal> superCowGrassMuncher = cowMethaneProducer;
            }
            {
                Cow myCow = new Cow("Geronimo");
                IGrassMuncher<Cow> cowGrassMuncher = myCow;
                IGrassMuncher<SuperCow> superCowGreassMuncher = cowGrassMuncher;
            }
            {
                List<Cow> cows = new List<Cow>();
                cows.Add(new Cow("Geronimo"));
                cows.Add(new SuperCow("Tonto"));
                ListAnimals(cows);
                Console.ReadLine();
            }
            {
                List<Cow> otherCows = new List<Cow>();
                otherCows.Add(new Cow("Geronimo"));
                otherCows.Add(new SuperCow("Tonto"));
                otherCows.Add(new Cow("Gerald"));
                otherCows.Add(new Cow("Phil"));
                otherCows.Sort(new AnimalNameLengthComparer());
                Console.ReadLine();
            }
        }

        public static void ListAnimals(IEnumerable<Animal> animals)
        {
            foreach (Animal animal in animals)
            {
                Console.WriteLine(animal.ToString());
            }
        }
    }
}
